package com.example.administrator.gitglide;

import android.animation.ValueAnimator;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;

public class MainActivity extends AppCompatActivity {
    ImageView imageView;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ValueAnimator animation = ValueAnimator.ofFloat(0f, 1000f);
        animation.setDuration(100000);

        animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator updatedAnimation) {
                // You can use the animated value in a property that uses the
                // same type as the animation. In this case, you can use the
                // float value in the translationX property.
                float animatedValue = (float)updatedAnimation.getAnimatedValue();
                imageView.setTranslationX(animatedValue);
                imageView.setRotation(animatedValue);


            }
        });





        imageView=findViewById(R.id.imageView);

        button=findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                Glide.with(MainActivity.this)
                        .load("")
                        .thumbnail(Glide.with(MainActivity.this).load(""))
                        .apply(RequestOptions.placeholderOf(R.mipmap.ic_launcher))//图片加载出来前，显示的图片
                        .apply(RequestOptions.circleCropTransform())//请求选项通过 RequestOptions 类和 apply() 方法来应用到程序中。
                        .apply(RequestOptions.bitmapTransform(new MultiTransformation<Bitmap>()))
                        .transform(new CenterCrop())
                        .transition(DrawableTransitionOptions.withCrossFade())//过渡选项
                        .dontAnimate()
                        .into(imageView);


                animation.start();
            }
        });

    }


    public void method(){
        /**
         * 1、简单用法
         */
     Glide.with(MainActivity.this)
            .load(R.mipmap.ic_launcher)
            .into(imageView);

        /**
         * 2、在 ListView 或 RecyclerView 中加载图片的代码和在单独的 View 中加载完全一样。
         * Glide 已经自动处理了 View 的复用和请求的取消：
         */
                /*
                @Override
                public void onBindViewHolder(ViewHolder holder, int position) {
                    String url = urls.get(position);
                    Glide.with(fragment)
                            .load(url)
                            .into(holder.imageView);
                }*/
        /**
         * 3、非 View 目标
         * 除了将 Bitmap 和 Drawable 加载到 View 之外，
         * 你也可以开始异步加载到你的自定义 Target 中：
         *
         * */
        Glide.with(this)
                .load("")
                .into(new CustomTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {

                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {

                    }
                });

    }









}
